Skip to content

fix: disable theme icon loading for battery display#390

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-battery-popup
Nov 26, 2025
Merged

fix: disable theme icon loading for battery display#390
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-battery-popup

Conversation

@wjyrich

@wjyrich wjyrich commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

Removed the code that attempts to load battery icons from system theme and now directly uses the built-in SVG icons. This change was necessary because the plugin currently does not support theme changes, and the theme icon loading was causing inconsistent battery icon display. The fallback mechanism now becomes the primary method for loading battery icons.

Log: Fixed inconsistent battery icon display in dock

Influence:

  1. Verify battery icons display correctly in different states (charging, low battery, etc.)
  2. Test battery percentage changes and corresponding icon updates
  3. Check that all battery level icons are properly rendered
  4. Verify no missing or broken battery icons in dock
  5. Test with different battery levels and charging states

fix: 禁用主题图标加载,使用内置电池图标

移除了从系统主题加载电池图标的代码,现在直接使用内置的SVG图标。此变更是
必要的,因为插件目前不支持主题变化,主题图标加载会导致电池图标显示不一
致。后备机制现在成为加载电池图标的主要方法。

Log: 修复了dock中电池图标显示不一致的问题

Influence:

  1. 验证不同状态下的电池图标显示正确(充电、低电量等)
  2. 测试电池百分比变化及对应的图标更新
  3. 检查所有电池电量图标是否正确渲染
  4. 验证dock中没有缺失或损坏的电池图标
  5. 测试不同电量水平和充电状态下的显示

PMS: BUG-342033

Summary by Sourcery

Bug Fixes:

  • Resolve inconsistent dock battery icon rendering caused by system theme icon loading and lack of theme-change support.

@sourcery-ai

sourcery-ai Bot commented Nov 26, 2025

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR disables loading battery icons from the system theme and always uses the bundled SVG battery icons as the primary source to ensure consistent rendering in the dock across all battery states.

Sequence diagram for updated battery icon refresh logic

sequenceDiagram
    actor DockUser
    participant PowerManager
    participant PowerApplet
    participant QSvgRenderer
    participant BatteryIconWidget

    DockUser->>PowerManager: Change battery state
    PowerManager-->>PowerApplet: batteryStateChanged(level, charging)
    PowerApplet->>PowerApplet: compute iconName and fallbackPath
    PowerApplet->>QSvgRenderer: QSvgRenderer(fallbackPath)
    QSvgRenderer-->>PowerApplet: renderer (validated)
    PowerApplet->>BatteryIconWidget: setPixmap(renderedSvgFrom(fallbackPath))
    BatteryIconWidget-->>DockUser: Updated battery icon displayed
Loading

Class diagram for PowerApplet battery icon rendering dependencies

classDiagram
    class PowerApplet {
        - m_batteryIcon : QLabel*
        + refreshBatteryIcon(icon : QString) void
    }

    class QLabel {
        + setPixmap(pixmap : QPixmap) void
        + size() QSize
    }

    class QSvgRenderer {
        + QSvgRenderer(filePath : QString)
        + isValid() bool
        + render(painter : QPainter) void
    }

    PowerApplet --> QLabel : updates
    PowerApplet --> QSvgRenderer : uses built_in_svg_icons
Loading

File-Level Changes

Change Details Files
Disable theme-based battery icon loading and always render from bundled SVG assets.
  • Commented out the logic that loads battery icons via QIcon::fromTheme and applies the theme pixmap to the battery label.
  • Updated the surrounding comment to explain that the plugin no longer follows theme changes and therefore defaults to built-in SVG icons.
  • Retained and relied on the existing QSvgRenderer-based path using internal resource URLs as the only code path for setting the battery icon.
plugins/dde-dock/power/powerapplet.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Since the theme icon loading path is intentionally disabled, consider removing the commented-out block entirely or replacing it with a clear TODO explaining under what conditions it should be re-enabled to avoid leaving dead code.
  • The new comment only states that the plugin does not follow theme changes; if behavior differs between light and dark modes or between themes using different battery icon designs, it may be worth clarifying this in the comment to make the rationale for forcing built-in SVGs more explicit for future maintainers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since the theme icon loading path is intentionally disabled, consider removing the commented-out block entirely or replacing it with a clear TODO explaining under what conditions it should be re-enabled to avoid leaving dead code.
- The new comment only states that the plugin does not follow theme changes; if behavior differs between light and dark modes or between themes using different battery icon designs, it may be worth clarifying this in the comment to make the rationale for forcing built-in SVGs more explicit for future maintainers.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Removed the code that attempts to load battery icons from system theme
and now directly uses the built-in SVG icons. This change was necessary
because the plugin currently does not support theme changes, and the
theme icon loading was causing inconsistent battery icon display. The
fallback mechanism now becomes the primary method for loading battery
icons.

Log: Fixed inconsistent battery icon display in dock

Influence:
1. Verify battery icons display correctly in different states (charging,
low battery, etc.)
2. Test battery percentage changes and corresponding icon updates
3. Check that all battery level icons are properly rendered
4. Verify no missing or broken battery icons in dock
5. Test with different battery levels and charging states

fix: 禁用主题图标加载,使用内置电池图标

移除了从系统主题加载电池图标的代码,现在直接使用内置的SVG图标。此变更是
必要的,因为插件目前不支持主题变化,主题图标加载会导致电池图标显示不一
致。后备机制现在成为加载电池图标的主要方法。

Log: 修复了dock中电池图标显示不一致的问题

Influence:
1. 验证不同状态下的电池图标显示正确(充电、低电量等)
2. 测试电池百分比变化及对应的图标更新
3. 检查所有电池电量图标是否正确渲染
4. 验证dock中没有缺失或损坏的电池图标
5. 测试不同电量水平和充电状态下的显示

PMS: BUG-342033
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我来对这段代码变更进行审查:

  1. 代码逻辑变更分析:
  • 原代码首先尝试从系统主题加载图标,如果失败则使用内置SVG图标作为fallback
  • 新代码直接使用内置SVG图标,移除了主题图标的加载逻辑
  • 注释说明了变更原因:插件目前不跟随主题变化
  1. 代码质量评估:
    优点:
  • 代码逻辑更简单直接
  • 减少了不必要的主题图标加载尝试
  • 注释清晰说明了变更原因

潜在问题:

  • 硬编码使用内置图标可能不够灵活
  • 如果未来需要支持主题切换,需要重新实现这部分逻辑
  1. 性能影响:
  • 移除了主题图标的加载尝试,减少了不必要的IO操作
  • 直接使用内置SVG文件,加载速度可能更快
  • 减少了QIcon相关的内存分配和转换操作
  1. 安全性考虑:
  • 使用固定的资源文件路径,减少了路径遍历等安全风险
  • 移除了外部主题文件的依赖,降低了潜在的安全隐患

改进建议:

  1. 考虑添加配置选项:
// 可以添加一个配置项来控制是否使用主题图标
if (m_useThemeIcons) {
    QIcon themeIcon = QIcon::fromTheme(iconName);
    if (!themeIcon.isNull()) {
        QPixmap pixmap = themeIcon.pixmap(m_batteryIcon->size());
        m_batteryIcon->setPixmap(pixmap);
        return;
    }
}
  1. 增加错误处理:
QSvgRenderer renderer(fallbackPath);
if (!renderer.isValid()) {
    qWarning() << "Failed to load battery icon:" << fallbackPath;
    // 可以设置一个默认的错误图标
    m_batteryIcon->setPixmap(QPixmap(":/batteryicons/batteryicons/error.svg"));
    return;
}
  1. 考虑添加图标缓存:
static QCache<QString, QPixmap> iconCache(10); // 缓存最近使用的10个图标
auto cachedPixmap = iconCache.object(fallbackPath);
if (cachedPixmap) {
    m_batteryIcon->setPixmap(*cachedPixmap);
    return;
}
  1. 建议在类中添加成员变量来控制图标加载策略:
private:
    bool m_useThemeIcons = false; // 可通过配置文件控制
    QCache<QString, QPixmap> m_iconCache;

这些改进可以让代码更加健壮和灵活,同时保持良好的性能。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy, wjyrich

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wjyrich

wjyrich commented Nov 26, 2025

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Nov 26, 2025

Copy link
Copy Markdown

This pr force merged! (status: behind)

@deepin-bot deepin-bot Bot merged commit f9a1e97 into linuxdeepin:master Nov 26, 2025
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants